﻿@model Eqwww.Web.Areas.SystemManage.Models.User.CreateViewModel
@{
    ViewData["Title"] = "Create";
    Layout = "~/Views/Shared/_ManageFormLayout.cshtml";
}



<form id="form1" class="mdui-m-t-3 mdui-m-b-3">
    <div asp-validation-summary="ModelOnly" class="mdui-textfield-error"></div>
    <div class="mdui-container">

        <div class="mdui-row">

            <div class="mdui-col-xs-12 mdui-col-md-6">

                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="UserName" class="mdui-textfield-label"></label>
                    <input asp-for="UserName" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="UserName" class="mdui-textfield-error"></span>
                </div>
            </div>
            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="RealName" class="mdui-textfield-label"></label>
                    <input asp-for="RealName" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="RealName" class="mdui-textfield-error"></span>
                </div>
            </div>

            <div class="mdui-col-xs-12 mdui-col-md-6">

                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="Contact" class="mdui-textfield-label"></label>
                    <input asp-for="Contact" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="Contact" class="mdui-textfield-error"></span>
                </div>
            </div>

            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield">
                    <label asp-for="UserType" class="mdui-textfield-label"></label>
                    <select asp-for="UserType" class="mdui-textfield-input mdui-color-grey-100" asp-items="@Html.GetEnumSelectList(typeof(Eqwww.Domain.Models.Identity.UserType))">
                        <option value="">==请选择==</option>
                    </select>
                    <i class="mdui-icon material-icons" style="position:absolute;right:0;">arrow_drop_down</i>
                    <span asp-validation-for="UserType" class="mdui-textfield-error"></span>
                </div>

            </div>

            <div id="Password_Box" class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="Password" class="mdui-textfield-label"></label>
                    <input asp-for="Password" type="password" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="Password" class="mdui-textfield-error"></span>
                </div>
            </div>

            <div id="RepeatPassword_Box" class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="RepeatPassword" class="mdui-textfield-label"></label>
                    <input asp-for="RepeatPassword" type="password" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="RepeatPassword" class="mdui-textfield-error"></span>
                </div>
            </div>

            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="Email" class="mdui-textfield-label"></label>
                    <input asp-for="Email" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="Email" class="mdui-textfield-error"></span>
                </div>
            </div>

            <div class="mdui-col-xs-12 mdui-col-md-6">
                <div class="mdui-textfield mdui-textfield-floating-label">
                    <label asp-for="SortCode" class="mdui-textfield-label"></label>
                    <input asp-for="SortCode" value="0" class="mdui-textfield-input mdui-color-grey-100" />
                    <span asp-validation-for="SortCode" class="mdui-textfield-error"></span>
                </div>
            </div>
            <style type="text/css">
                .eq-avatar-choose-box img {
                    width: 64px;
                    cursor: pointer;
                }

                .eq-avatar-choosed-box img {
                    width: 128px;
                }
            </style>
            <div class="mdui-col-xs-12">
                <div class="mdui-typo-body-2">用户头像</div>
                <div class="eq-avatar-choose-box">
                    <img src="~/images/avatars/default.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-11.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-12.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-13.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-14.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-15.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-16.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-17.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-18.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-19.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-20.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-21.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-22.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-23.png" class="mdui-img-circle" />
                    <img src="~/images/avatars/avatar-24.png" class="mdui-img-circle" />
                </div>
                <div class="eq-avatar-choosed-box">
                    <img src="~/images/avatars/default.png" class="mdui-img-circle" />
                </div>
                <input type="hidden" asp-for="Avatar" />
            </div>

        </div>

    </div>
</form>


@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}

    <script>

        var postId = $.request('postid');

        $(function () {
            $('#Avatar').val('/images/avatars/default.png');
            $('.eq-avatar-choose-box img').click(function () {
                var $this = $(this);
                $('.eq-avatar-choosed-box img').attr('src', $this.attr('src'));
                $('#Avatar').val($this.attr('src'));
            });


            $('#UserType').change(function () {
                var $this = $(this);
                if ($this.val() == "1") {
                    $('#Password').val('');
                    $('#RepeatPassword').val('');
                    $('#Password_Box').hide();
                    $('#RepeatPassword_Box').hide();
                }
                else {
                    $('#Password_Box').show();
                    $('#RepeatPassword_Box').show();
                }
            });
        });


        function submitForm() {

            if (!$("#form1").valid()) {
                return false;
            }

            if ($('#UserType').val() == "0") {
                var Password = $('#Password').val();
                var RepeatPassword = $('#RepeatPassword').val();
                if (Password == '' || RepeatPassword == '') {
                    $.modalAlert('【本地账户】类型【密码】和【重复密码】不能为空！');
                    return false;
                }

                if (Password != RepeatPassword) {
                    $.modalAlert('两次输入密码不一致！');
                    return false;
                }
            }
            else if ($('#UserType').val() == "1") {
                var Password = $('#Password').val();
                var RepeatPassword = $('#RepeatPassword').val();
                if (Password != '' || RepeatPassword != '') {
                    $.modalAlert('【RTX账户】类型【密码】和【重复密码】必须为空！');
                    return false;
                }
            }


            var postData = $('#form1').formSerialize();

            $.submitForm({
                url: "/SystemManage/User/Create?postId=" + postId,
                param: postData,
                success: function () {
                    $.currentWindow().location.reload();
                }
            });

        };
    </script>
}

